//
//  UIButton-Extension.swift
//  JMWB
//
//  Created by 个人电脑 on 16/3/14.
//  Copyright © 2016年 个人电脑. All rights reserved.
//

import UIKit

extension UIButton{
    
    // swift中如果在extension中扩展构造函数,必须在构造函数前convenience(便利)
    // 便利构造函数中,必须明确调用self.init()
    convenience init(imageName : String, bgImageName : String){
        self.init()
    
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        
        sizeToFit()

    }
 /*
// 在swift中类方法只需要以class开头即可:类似于OC中+开头的方法
//提供一个类方法,跟OC思想相近,不常使用
    class func createBtn(imageName : String, bgImageName : String) -> UIButton{
        let btn = UIButton(type: .Custom)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        btn.setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
        
        btn.sizeToFit()
        return btn
    }
*/
}
